<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<title></title>
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport"
			content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
		<link rel="stylesheet" href="../../../layuiadmin/layui/css/layui.css" media="all">
		<link rel="stylesheet" href="../../../layuiadmin/style/admin.css" media="all">
		<link rel="stylesheet" href="../../../css/common.css" media="all">

	</head>

	<style type="text/css">
		th,
		td {
			padding: .3rem;
			white-space: nowrap;
		}

		.table_box input {
			border: none;
			text-align: center;
		}


		.table_box input::-webkit-outer-spin-button,
		.table_box input::-webkit-inner-spin-button {
			-webkit-appearance: none;
		}

		.table_box input[type="number"] {
			-moz-appearance: textfield;
		}


		.addtext {
			display: block;
			margin: 0 auto;
			width: 20px;
			height: 20px;
			color: #FFF;
			line-height: 20px;
			background-color: #444;
			border-radius: 4px;
			cursor: pointer;
			text-align: center;
			user-select: none;
		}

		.deltext {
			display: block;
			margin: 0 auto;
			width: 20px;
			height: 20px;
			color: #FFF;
			line-height: 20px;
			background-color: #444;
			border-radius: 4px;
			cursor: pointer;
			text-align: center;
			user-select: none;
		}

		.deltext:last-child {
			display: block;
		}
	</style>

	<body>

		<div class="layui-fluid">
			<div class="layui-row" id="view">
				<form class="layui-form" wid100 lay-filter="test_detail">
					<div class="layui-card">
						<div class="layui-card-body">
							<div class="layui-form-item">
								<label class="layui-form-label">订单编号：</label>
								<div class="layui-input-block">
									<input type="text" readonly="readonly" name="orderid" autocomplete="off"
										class="layui-input border_transparent">
								</div>
							</div>
							<!--<div class="layui-form-item">
								<label class="layui-form-label">快递公司：</label>
								<div class="layui-input-block">
									<select name="delivery_id" lay-filter="delivery_unit" class="delivery_unit" lay-verify="required"></select>
								</div>
							</div>-->


							<!--非机具不显示-->
							<div class="layui-form-item" id="product" style="display: none;">
								<label class="layui-form-label"><span class='text_red_color'>*</span>产品类型：</label>
								<div class="layui-input-block product"></div>
							</div>
							<!-- 非物料订单不显示 -->
							<div class="layui-form-item" style="display: none;" id="pos_sn_supplier">
								<label class="layui-form-label"><text class='text_red_color'>*</text>供应商选择：</label>
								<div class="layui-input-inline">
									<input type="text" name="supplier_name" placeholder="选择供应商选择" autocomplete="off"
										class="layui-input supplier_name">
									<input type="hidden" name="supplierid" autocomplete="off"
										class="layui-input supplierid">
								</div>
								<div class="layui-form-mid layui-word-aux">
									<a href="Javascript:;" onclick="supplier()">选择</a>
								</div>
							</div>

							<div class="layui-form-item" style="display: none;" id="pos_sn_pre">
								<label class="layui-form-label">机身编号：</label>
								<div class="layui-input-block">
									<input type="text" name="pos_sn_pre" placeholder="请输入支付公司及产品类型(例:K205T0H)"
										autocomplete="off" class="layui-input">
								</div>
							</div>
							<div class="layui-form-item" style="display: none;" id="sn">
								<div class="layui-inline">
									<label class="layui-form-label">序列号范围：</label>
									<div class="layui-input-inline" style="width: 100px;">
										<input type="text" name="sn_start" placeholder="开始序列号" autocomplete="off"
											class="layui-input">
									</div>
									<div class="layui-form-mid">-</div>
									<div class="layui-input-inline" style="width: 100px;">
										<input type="text" name="sn_end" placeholder="结束序列号" autocomplete="off"
											class="layui-input">
									</div>
									<button type="button" class="layui-btn layui-btn-normal"
										onclick="createnum()">生成</button>
								</div>
							</div>
							<div class="layui-form-item" style="display: none;" id="pos_sn">
								<label class="layui-form-label">机具序列号：</label>
								<div class="layui-input-block">
									<textarea placeholder="请输入机具序列号" name="pos_sn" class="layui-textarea"></textarea>
								</div>
							</div>


							<div class="layui-form-item" style="display: none;" id="pos_fx">
								<label class="layui-form-label">返现设置：</label>
								<div class="layui-input-block">
									<div class="form-one">
										<table class="table_box" border="1" style="width: 100%;text-align: center;">
											<tr>
												<th>阶段</th>
												<th>达标金额</th>
												<th>返现金额</th>
												<th>到期返现金额</th>
												<th>返现红包</th>
												<th>到期返现红包</th>
												<th>开始(天)</th>
												<th>结束(天)</th>
												<th>操作</th>
											</tr>
											<tr class="tableli1">
												<td>
													<input name="oid" type="number" disabled="disabled"
														autocomplete="off" class="layui-input" value="1">
												</td>
												<td>
													<input name="amount" type="number" placeholder="请输入达标金额"
														autocomplete="off" class="layui-input">
												</td>
												<td>
													<input name="back_amount" type="number" placeholder="请输入返现金额"
														autocomplete="off" class="layui-input">
												</td>
												<td>
													<input name="back_expire_amount" type="number"
														placeholder="请输入到期返现金额" autocomplete="off" class="layui-input">
												</td>
												<td>
													<input name="back_packet" type="number" placeholder="请输入返现红包"
														autocomplete="off" class="layui-input">
												</td>
												<td>
													<input name="back_expire_packet" type="number"
														placeholder="请输入到期返现红包" autocomplete="off" class="layui-input">
												</td>
												<td>
													<input name="startday" type="number" placeholder="请输入开始时间"
														autocomplete="off" class="layui-input" value="1">
												</td>
												<td>
													<input name="endday" type="number" placeholder="请输入截止时间"
														autocomplete="off" class="layui-input" value="30">
												</td>
												<td>
													<span class="addtext" id="table1">+</span>
												</td>
											</tr>
										</table>
									</div>
								</div>
							</div>

							<div class="layui-form-item" style="display: none;" id="back_expire">
								<label class="layui-form-label">返现到期<span style="color: red;">*</span>：</label>
								<div class="layui-input-block">
									<input type="text" name="back_expire" id="date" placeholder="返现到期"
										autocomplete="off" class="layui-input">
								</div>
							</div>

							<div class="layui-form-item" style="display: none;" id="service_fee">
								<label class="layui-form-label">服务金额：</label>
								<div class="layui-input-block">
									<input type="text" name="service_fee" placeholder="请输入服务金额" autocomplete="off"
										class="layui-input">
								</div>
							</div>
							<!--非机具不显示-->




							<div class="layui-form-item">
								<div class="layui-inline" style="display: none;">
									<label class="layui-form-label">快递公司</label>
									<div class="layui-input-inline">
										<input type="text" name="delivery_id" placeholder="快递公司" autocomplete="off"
											class="layui-input" readonly="">
									</div>
								</div>
								<div class="layui-inline">
									<label class="layui-form-label">快递公司简称</label>
									<div class="layui-input-inline">
										<input type="text" name="delivery_no" placeholder="快递公司" autocomplete="off"
											class="layui-input" readonly lay-verify="required">
									</div>
								</div>
								<div class="layui-inline">
									<label class="layui-form-label">快递公司名称</label>
									<div class="layui-input-inline">
										<input type="text" name="delivery_name" placeholder="快递公司名称" autocomplete="off"
											class="layui-input" readonly>
									</div>
									<div class="layui-form-mid layui-word-aux"><a href="Javascript:;"
											onclick="searchdata('spuid')">选择</a></div>
								</div>
							</div>


							<div class="layui-form-item">
								<label class="layui-form-label">快递单号：</label>
								<div class="layui-input-block">
									<input type="text" name="delivery_waybill" lay-verify="required"
										placeholder="请输入快递单号" autocomplete="off" class="layui-input">
								</div>
							</div>

							<div class="layui-form-item">
								<label class="layui-form-label">图片</label>
								<div class="layui-input-block">
									<button type="button" class="layui-btn layui-btn-normal" id="icon_btn">上传图片</button>
									<span>只上传一张即可</span>
									<blockquote class="layui-elem-quote layui-quote-nm" style="margin-top: 10px;">
										预览图：
										<div class="layui-upload-list upload_list" id="icon_box">
											<!-- <li id="2222"><img class="layui-upload-img" src="https://lishuahuoban-1259416407.image.myqcloud.com/bdf35814c3be45df915e6fc19c3e72df.jpg" alt="https://lishuahuoban-1259416407.image.myqcloud.com/bdf35814c3be45df915e6fc19c3e72df.jpg"><i class="close_icon layui-icon layui-icon-close-fill"></i> <p class="success"> <i class="layui-icon layui-icon-ok-circle"></i> <i class="layui-icon layui-icon-refresh"></i> 上传成功</p></li> -->
										</div>
									</blockquote>
									<!-- <button type="button" class="layui-btn layui-btn-normal" onclick="choose(1)">上传图片</button>
									<ul class="show_img_ul" id="img"></ul> -->
								</div>
							</div>

							<!--delivery_url-->
							<div class="layui-form-item">
								<label class="layui-form-label">系统备注：</label>
								<div class="layui-input-block">
									<input type="text" name="op_remark" placeholder="请输入系统备注" autocomplete="off"
										class="layui-input">
								</div>
							</div>

						</div>
					</div>
					<div class="layui-form-item layui-layout-admin">
						<div class="layui-input-block">
							<div class="layui-footer" style="left: 0;">
								<button class="layui-btn" lay-submit="" lay-filter="demo1">立即提交</button>
							</div>
						</div>
					</div>
				</form>
			</div>
		</div>
		<script src="../../../layuiadmin/layui/layui.js"></script>
		<script src="../../../js/jquery.min.js"></script>
		<script src="../../../js/jquery.jqprint-0.3.js"></script>
		<script src="../../../js/common.js"></script>
		<script>
			var _data = {
				id: getParam('id'),
				orderid: getParam('orderid'),
				quantity: getParam('quantity'),
				to_agent_id: getParam('memberid'),
				specname: getParam('specname'),
				type: getParam('type')
			}
			$('input[name=orderid]').val(_data.orderid);
			$('input[name=quantity]').val(_data.quantity);
			$('input[name=specname]').val(_data.specname);

			var pos_sn_arr = [];
			layui.config({
				base: '../../../layuiadmin/' //静态资源所在路径
			}).extend({
				index: 'lib/index' //主入口模块
			}).use(['index', 'form', 'laytpl', 'laydate', 'uploadnew'], function() {
				var $ = layui.$,
					admin = layui.admin,
					laytpl = layui.laytpl,
					laydate = layui.laydate,
					uploadnew = layui.uploadnew,
					form = layui.form;
				delivery_show();
				// console.log(_data.type, '00000')
				if (_data.type != 'undefined' && _data.type == 2) {

					var product = document.getElementById("product");
					var pos_sn_supplier = document.getElementById("pos_sn_supplier");
					var pos_sn_pre = document.getElementById("pos_sn_pre");
					var sn = document.getElementById("sn");
					var pos_sn = document.getElementById("pos_sn");
					var pos_fx = document.getElementById("pos_fx");
					var back_expire = document.getElementById("back_expire");
					var service_fee = document.getElementById("service_fee");



					product.style.display = "block";
					pos_sn_supplier.style.display = "block";
					pos_sn_pre.style.display = "block";
					sn.style.display = "block";
					pos_sn.style.display = "block";
					pos_fx.style.display = "block";
					back_expire.style.display = "block";
					service_fee.style.display = "block";
				}

				initproductshow1('radio')

				initradio()

				function initradio() {
					setTimeout(() => {
						$("input[name=product][value=4dec2d5ebdce47148cd7d987ee27bd0f]").prop("checked", "true");
						form.render();
					}, 1000)
				}


				laydate.render({
					elem: '#date'
				});


				form.on('select(delivery_unit)', function(data) {
					_data.delivery_name = data.elem[data.elem.selectedIndex].innerHTML;
				});

				window.supplier = function(type) {
					layer.open({
						type: 2,
						title: '选择供应商',
						shadeClose: false,
						shade: 0.5,
						maxmin: true, //开启最大化最小化按钮
						area: ['50%', '50%'],
						content: '../member_pos/model/supplier_information.html',
						end: function() {},
						success: function() {}
					});
				}


				window.distpalyNone = function() {
					let pos_sn_supplier = document.getElementById('pos_sn_supplier') // 供应商选择
					let pos_sn_pre = document.getElementById('pos_sn_pre') // 机身编号
					let sn = document.getElementById('sn') // 系列号范围
					let pos_sn = document.getElementById('pos_sn') // 机具系列号
					let pos_fx = document.getElementById('pos_fx') // 返现到期
					let back_expire = document.getElementById('back_expire') // 服务金额

					pos_sn_supplier.style.display = 'none'
					pos_sn_pre.style.display = 'none'
					sn.style.display = 'none'
					pos_sn.style.display = 'none'
					pos_fx.style.display = 'none'
					back_expire.style.display = 'none'
				}


				window.createnum = function() {

					var pos_sn_pre = $('input[name=pos_sn_pre]').val(),
						sn_start = $('input[name=sn_start]').val(),
						sn_end = $('input[name=sn_end]').val();

					if (!pos_sn_pre) {
						layer.msg('请输入机身编号')
					} else if (!sn_start || sn_start.length > 4 || !zorenumReg.test(Number(sn_start))) {
						// console.log(zorenumReg.test(sn_start));
						layer.msg('开始序列号必须为小于4位的纯数字')
					} else if (!sn_end || sn_end.length > 4 || !zorenumReg.test(Number(sn_end))) {
						layer.msg('结束序列号必须为小于4位的纯数字')
					} else if (sn_start >= sn_end) {
						layer.msg('结束序列号必须大于等于开始序列号')
					} else {
						var numlength = Number(sn_end) - Number(sn_start),
							pos_sn_html = ''

						for (var i = 0; i <= numlength; i++) {
							var pos_sn = String(Number(sn_start) + Number(i))
							pos_sn_html += (',' + pos_sn_pre + PrefixInteger(pos_sn, 4)).replace(/ /g, '')
							/* pos_sn_arr.push({
								'pos_sn': pos_sn_pre + PrefixInteger(pos_sn,4)
							}) */
						}
						if (pos_sn_html != '') pos_sn_html.substring(1);
						$('textarea[name=pos_sn]').val(pos_sn_html)
					}
				}

				/* 主图上传 */
				var img_option = {
					btnelem: '#icon_btn',
					filebox: '#icon_box',
					url: server.upimg,
				}
				uploadnew.initupload(img_option, 1)
				//监听提交
				form.on('submit(demo1)', function(data) {
					if (_data.type != 'undefined' && _data.type != 5) {

						var tools = $('textarea[name=pos_sn]').val();
						tools = tools.split(",");

						pos_sn_arr = [];
						var pos_sn = tools;
						for (var i = 0; i < pos_sn.length; i++) {
							if (pos_sn[i]) {
								pos_sn_arr.push({
									'pos_sn': pos_sn[i].replace(/ /g, '')
								})
							}
						}
						_data.pos_data = JSON.stringify(pos_sn_arr);
						if (tools.length - 1 == _data.quantity) {
							layer.msg('机具数量与订购数量不一致');
						} else {
							$.fn.serializeObject = function() {
								var o = {};
								var a = $(this).find('input')
								$.each(a, function() {
									if (o[this.name]) {
										if (!o[this.name].push) {
											o[this.name] = [o[this.name]];
										}
										o[this.name].push(this.value || '');
									} else {
										o[this.name] = this.value || '';
									}
								});
								return o;
							}
							var json = [];
							$(".tableli1").each(function() {
								json.push($(this).serializeObject())
							})

							var back_amounts = [];
							var back_expire_amounts = [];
							var back_packets = [];
							var back_expire_packets = [];
							if (json.length != 0) {
								for (let k = 0; k < json.length; k++) {
									back_amounts.push(json[k].back_amount)
									back_expire_amounts.push(json[k].back_expire_amount)
									back_packets.push(json[k].back_packet)
									back_expire_packets.push(json[k].back_expire_packet)
								}
								back_amounts = back_amounts.join(',')
								back_expire_amounts = back_expire_amounts.join(',')
								back_packets = back_packets.join(',')
								back_expire_packets = back_expire_packets.join(',')
							}

							json = JSON.stringify(json)
							_data.back_config = json
							var data = data.field;
							_data = Object.assign(_data, data);

							_data.back_amount = back_amounts
							_data.back_expire_amount = back_expire_amounts
							_data.back_packet = back_packets
							_data.back_expire_packet = back_expire_packets
							var lock = false
							layer.confirm('确定要提交数据？', function() {
								if (!lock) {
									lock = true
									submitdata();
								}
							});
						}
					} else {
						var data = data.field;
						_data = Object.assign(_data, data);
						var lock = false
						layer.confirm('确定要提交数据？', function() {
							if (!lock) {
								lock = true
								submitdata();
							}
						});
					}
					return false;
				});

				function submitdata() {
					_data.delivery_url = uploadnew.initupload(img_option, 3).join(',')

					// shop_orders_delivery
					// updateorders_delivery
					let body = JSON.parse(JSON.stringify(_data))
					$.post(server.shop_orders_delivery, body, function(res, status) {
						if (status == 'success') {
							if (res.code == 0) {
								layer.alert('操作成功', function() {
									parent.layer.closeAll();
									parent.layui.table.reload('test-table-operate');
								});
							} else {
								closeloading();
								layer.msg(res.msg);
							}
						} else {
							layer.msg('服务器连接错误');
						}
					});
				}

				window.searchdata = function(type) {
					switch (type) {
						case 'spuid':
							layer.open({
								type: 2,
								title: '选择快递单位',
								shadeClose: false,
								shade: 0.5,
								maxmin: true, //开启最大化最小化按钮
								area: ['800px', '90%'],
								content: 'choose_delivery.html',
								end: function() {
									setTimeout(function() {
										productdetail(_data.spuid)
									}, 300)
								},
								success: function() {}
							});
							break;
						default:
							break;
					}
				}


				var is1 = 1;
				var astime = 1;
				var dstime = 30;
				$('#table1').on('click', function() {
					is1++;
					let ass = (is1 - 1) * 30 + 1;
					let dss = dstime * is1;

					let html = `
						<tr class="tableli1">
							<td>
								<input name="oid" type="number" disabled="disabled" autocomplete="off" class="layui-input" value="${is1}">
							</td>
							<td>
								<input name="amount" type="number" placeholder="请输入达标金额" autocomplete="off" class="layui-input">
							</td>
							<td>
								<input name="back_amount" type="number" placeholder="请输入返现金额" autocomplete="off" class="layui-input">
							</td>
							<td>
								<input name="back_expire_amount" type="number" placeholder="请输入到期返现金额" autocomplete="off" class="layui-input">
							</td>
							<td>
								<input name="back_packet" type="number" placeholder="请输入返现红包" autocomplete="off" class="layui-input">
							</td>
							<td>
								<input name="back_expire_packet" type="number" placeholder="请输入到期返现红包" autocomplete="off" class="layui-input">
							</td>
							<td>
								<input name="startday" type="number" placeholder="请输入开始时间" autocomplete="off" class="layui-input" value="${ass}">
							</td>
							<td>
								<input name="endday" type="number" placeholder="请输入截止时间" autocomplete="off" class="layui-input" value="${dss}">
							</td>
							<td>
								<span class="deltext deltext1">-</span>
							</td>
						</tr>
					`

					$('.deltext1').css('display', 'none')
					$('.tableli1:last').after(html)


					$(".deltext1").unbind("click");
					$(".deltext1").each(function(i) {
						$(this).click(function() {
							$(this).parent().parent().remove();
							is1 = $('.tableli1').length
							let list = $('.tableli1')
							if (is1 != 1) {
								for (let i = 0; i < is1; i++) {
									$(list[i]).find('td:first').html(i + 1)
								}
							}


							$('.deltext:last').css('display', 'block')
						});
					});
				})

			});
		</script>
	</body>

</html>
